﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WF_Array
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
        //点击第一个按钮进行的操作
        private void button1_Click(object sender, EventArgs e)
        {   //每点击刷新错误提示
            label2.Text= string.Empty;
            //获取textBox的内容
            string n = textBox1.Text;
            int num=0;
            bool judge=int.TryParse(n, out num);
            
            if (judge)//合法输入则加入数组
            {
                Program.nums.Add(num);
                label2.Text = "数据录入成功";
            }
            else//若用户非法输入，出现提示
            {
                label2.Text = "非法的输入，录入失败";
            }
            textBox1.Text = string.Empty;
            
        }
        //数组输入完毕
        private void button2_Click(object sender, EventArgs e)
        {
            //如果数组为空
            if (Program.nums.Count == 0)
            {
                label3.Text = "当前数组为空";
            }
            //如果数组不为空，调用方法
            else
            {
               
                label3.Text = "数组分析结果如下：";
                label4.Text = "数组包含元素："+Program.showNums();
                label5.Text = "数组最大值为：" + Convert.ToString(Program.getMax()) ;
                label6.Text = "数组最小值为：" +Convert.ToString(Program.getMin()); 
                label7.Text = "数组平均值为：" +Convert.ToString(Program.getAverage());
                label7.Text = "数组和为：" + Convert.ToString(Program.getSum()); 
            }

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }
    }
}
